package Day05;

import java.util.Arrays;

public class ArrayDemo {
    public static void main(String[] args) {
        /*int[] a =new int[5];
        double[]b=new double[10];
        boolean[]c=new boolean[20];
        int[]arr2={2,5,8};
        int[]arr3=new int[]{2,5,8};
        int[]arr4;
        arr4=new int[]{2,5,8};

        int[] arr=new int[3];
        System.out.println(arr.length);
        System.out.println("第一个元素是"+arr[0]);
        arr[0]=100;
        arr[1]=200;
        arr[2]=300;
        System.out.println("第一个元素是"+arr[0]);
        System.out.println("第二个元素是"+arr[1]);
        System.out.println("第三个元素是"+arr[2]);
        System.out.println("最后一个元素是"+arr[arr.length-1]);

        int[] ac=new int[5];
        System.out.println(ac.length);
        ac[0]=2;
        ac[1]=4;
        ac[2]=6;
        ac[3]=8;
        ac[4]=10;
        System.out.println("第一个元素是"+ac[0]);
        System.out.println("最后一个元素是"+ac[ac.length-1]);
         */
        //数组的遍历/迭代
        /*int[]arr=new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i]=(int)(Math.random()*100);
            System.out.println(arr[i]);
        }

         */
        /*int[]a={10,20,30,40,50};
        int[]b=new int[6];
        System.arraycopy(a,1,b,0,4);
        for (int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }

         */
        int[]a={10,20,30,40,50};
        int[]b= Arrays.copyOf(a,4);
        for (int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }
        a=Arrays.copyOf(a,a.length+1);
        for (int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }

    }
}
